package com.tqz.juc.synchronizeds;

import lombok.extern.slf4j.Slf4j;
import org.openjdk.jol.info.ClassLayout;

/**
 * <p>测试偏向锁、轻量级锁
 *
 * @author tianqingzhao
 * @since 2022/1/19 18:43
 */
@Slf4j
public class T0_BasicLock {
    
    public static void main(String[] args) {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Object o = new Object();
        log.info("第一次打印：{}", ClassLayout.parseInstance(o).toPrintable());
        
        new Thread(() -> {
            synchronized (o) {
                log.info("第二次打印：{}", ClassLayout.parseInstance(o).toPrintable());
            }
        }).start();
        
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        
        log.info("第三次打印：{}", ClassLayout.parseInstance(o).toPrintable());
        new Thread(() -> {
            synchronized (o) {
                log.info("第四次打印：{}", ClassLayout.parseInstance(o).toPrintable());
            }
        }).start();
    }
}
